import { wxRequest } from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()

Page({
  data: {
    datalist: [],
    isEdit: -1
  },

  onLoad: function (options) { 
    if (options.isEdit) {
      this.data.isEdit = options.isEdit
    }
    this.getlist();
  },

  // 获取列表
  getlist: function () {
    var that = this
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + "/org/protected/bizOrg/findAgentList",
      method: "post",
      data: {
        keyword: that.data.keywords,
        status: 1,
        pageSize: 10000
      }
    }, function (res) {
      console.log(res)
      that.setData({
        datalist: res.list
      })
    })
  },


  //监听搜索
  seacherOn: function (e) {
    var keywords = e.detail
    this.setData({
      keywords
    })
    this.getlist()
  },


  //选择供应商
  choose: function (e) {
    console.log('choose', e)
    var item = e.currentTarget.dataset.item

    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面    
    prevPage.setData({
      agentItem: item,
    })
    if (this.data.isEdit == 0) {
      prevPage.setData({
        isEdit: true
      })
    }
    wx.navigateBack();
  },


})